package cn.com.agree.contractcenter.application.contracttemplate.service;

import cn.com.agree.contractcenter.application.contracttemplate.assembler.ContractTemplateAssembler;
import cn.com.agree.contractcenter.application.contracttemplate.dto.ContractTemplateRequestDTO;
import cn.com.agree.contractcenter.application.contracttemplate.dto.ContractTemplateResponseDTO;
import cn.com.agree.contractcenter.domain.contracttemplate.entity.ContractTemplate;
import cn.com.agree.contractcenter.domain.contracttemplate.support.repository.ContractTemplateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author chenrui
 * @description 合约模板服务
 * @date 2022/10/12
 */
@Service
public class ContractTemplateService {

    @Autowired
    private ContractTemplateAssembler contractTemplateAssembler;

    @Autowired
    private ContractTemplateRepository contractTemplateRepository;

    /**
     * 新建合约模板
     * @param contractTemplateRequestDTO
     * @return
     */
    public ContractTemplateResponseDTO createContractTemplate(ContractTemplateRequestDTO contractTemplateRequestDTO){
        ContractTemplate contractTemplate = contractTemplateAssembler.toEntity(contractTemplateRequestDTO);
        contractTemplateRepository.saveContractTemplate(contractTemplate);
        return null;
    }

    /**
     * 根据合约模板ID查询合约模板
     * @param id
     * @return
     */
    public ContractTemplateResponseDTO queryContractTemplate(Integer id){
        ContractTemplate contractTemplate = contractTemplateRepository.findContractTemplateById(id);
        return contractTemplateAssembler.toDTO(contractTemplate);
    }

}
